package com.ly.controller;

import com.ly.constant.ResultCodeConstant;
import com.ly.pojo.domain.ConfigDO;
import com.ly.pojo.domain.MaintenanceLogDO;
import com.ly.pojo.dto.BackupDTO;
import com.ly.pojo.dto.ConfigDTO;
import com.ly.pojo.dto.CreateGroup;
import com.ly.pojo.dto.MaintenanceLogDTO;
import com.ly.pojo.dto.OperationLogDTO;
import com.ly.pojo.dto.RestResult;
import com.ly.pojo.dto.UpdateGroup;
import com.ly.pojo.query.ConfigQuery;
import com.ly.pojo.query.MaintenanceLogQuery;
import com.ly.pojo.query.QueryGroup;
import com.ly.service.ConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统配置管理模块
 *
 * @author Administrator
 * @date 2025-03-07 10:51:13
 */
@Tag(name = "系统配置管理模块")
@RequestMapping("config")
@RestController
public class ConfigController {

    @Autowired
    private ConfigService configService;

    /**
     * 修改系统配置
     *
     * @param configDTO 修改系统配置入参
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "修改系统配置")
    @ResponseBody
    public RestResult<Boolean> updateConfig(@RequestBody @Validated(UpdateGroup.class) ConfigDTO configDTO) {
        Boolean result = configService.updateConfig(configDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取系统配置
     *
     * @param configQuery 获取系统配置入参
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "获取系统配置")
    public RestResult<ConfigDO> getConfig(@Validated(QueryGroup.class) ConfigQuery configQuery) {
        ConfigDO result = configService.getConfig(configQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 创建数据备份
     *
     * @param backupDTO 数据备份入参
     * @return
     */
    @RequestMapping(value = "/backup", method = RequestMethod.POST)
    @Operation(summary = "创建数据备份")
    @ResponseBody
    public RestResult<Boolean> createBackup(@RequestBody @Validated(CreateGroup.class) BackupDTO backupDTO) {
        Boolean result = configService.createBackup(backupDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 恢复数据备份
     *
     * @param backupDTO 数据备份入参
     * @return
     */
    @RequestMapping(value = "/restore", method = RequestMethod.PUT)
    @Operation(summary = "恢复数据备份")
    @ResponseBody
    public RestResult<Boolean> restoreBackup(@RequestBody @Validated(UpdateGroup.class) BackupDTO backupDTO) {
        Boolean result = configService.restoreBackup(backupDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 记录系统维护日志
     *
     * @param logDTO 记录系统维护日志入参
     * @return
     */
    @RequestMapping(value = "/maintenance-log", method = RequestMethod.POST)
    @Operation(summary = "记录系统维护日志")
    @ResponseBody
    public RestResult<Boolean> recordMaintenanceLog(@RequestBody @Validated(CreateGroup.class) MaintenanceLogDTO logDTO) {
        Boolean result = configService.recordMaintenanceLog(logDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取系统维护日志
     *
     * @param logQuery 获取系统维护日志入参
     * @return
     */
    @RequestMapping(value = "/maintenance-logs", method = RequestMethod.GET)
    @Operation(summary = "获取系统维护日志")
    public RestResult<List<MaintenanceLogDO>> getMaintenanceLogs(@Validated(QueryGroup.class) MaintenanceLogQuery logQuery) {
        List<MaintenanceLogDO> result = configService.getMaintenanceLogs(logQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 记录后台操作日志
     *
     * @param logDTO 记录后台操作日志入参
     * @return
     */
    @RequestMapping(value = "/operation-log", method = RequestMethod.POST)
    @Operation(summary = "记录后台操作日志")
    @ResponseBody
    public RestResult<Boolean> recordOperationLog(@RequestBody @Validated(CreateGroup.class) OperationLogDTO logDTO) {
        Boolean result = configService.recordOperationLog(logDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
